//
//  VisitorLoginView.swift
//  lixiangweibo
//
//  Created by dyy on 15/11/24.
//  Copyright © 2015年 lixianggongzuoshi. All rights reserved.
//



import UIKit
//设置代理
protocol visitorLoginViewDelegate : NSObjectProtocol{

//设置代理方法
    func visitorViewLoginViewDidSelected()
    func visitorViewRegisterViewDidSelected()

}



class VisitorLoginView: UIView {
    //旋转图
    @IBOutlet weak var smallIconView: UIImageView!
    //中间大图
    @IBOutlet weak var IconView: UIImageView!
    
    @IBOutlet weak var MessageLabel: UILabel!
    //设置代理属性
    var delegate : visitorLoginViewDelegate?
    
    func setUpInfo(imageName: String,message: String,isHome: Bool){
        
        startAnimation()
        //
        IconView.hidden = !isHome
        if isHome{
            //设置中间图片
            IconView.image = UIImage(named: imageName)
            //bringSubviewToFront(IconView)
        }
        else{
        //设置旋转图片
        smallIconView.image = UIImage(named: imageName)
        bringSubviewToFront(smallIconView)
        }
//        if isHome {
//        startAnimation()
//        }
//        else{
//        
//        stopAnimation()
//        }
        //三目运算是否要开始动画
        isHome ? startAnimation() : stopAnimation()
        //设置label
        MessageLabel.text = message
        
        
        
    
    }
    
    //开始动画
    func startAnimation(){
    
        //初始化动画方式,并制定方式
    let animation = CABasicAnimation(keyPath: "transform.rotation")
        //动画范围
        animation.toValue = 2 * M_PI
        //重复次数
        animation.repeatCount = MAXFLOAT
        //动画时长
        animation.duration = 15
        //设置动画
        smallIconView.layer.addAnimation(animation, forKey: nil)
    }
    //停止动画
    func stopAnimation(){
    
        smallIconView.layer.removeAllAnimations()
    
    }
    //注册
    @IBAction func regiester() {
        
        delegate?.visitorViewRegisterViewDidSelected()
    
    }
    //登录
    @IBAction func login() {
        
        delegate?.visitorViewLoginViewDidSelected()
    }
    
}
